package org.fengling.readingplatform.note.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.fengling.readingplatform.model.entity.note.Note;
import org.fengling.readingplatform.note.mapper.NoteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.fengling.readingplatform.note.service.NoteService;

import java.util.List;

@Service
public class NoteServiceImpl implements NoteService {

    @Autowired
    private NoteMapper noteMapper;

    // 保存笔记的方式
    @Override
    public void save(Note note) {
        noteMapper.save(note);
    }

    // 笔记列表的方法
    @Override
    public PageInfo<Note> findByPage(Integer pageNum, Integer pageSize) {
        // 设置分页参数
        PageHelper.startPage(pageNum, pageSize);
        // 根据条件查询所有数据
        List<Note> list = noteMapper.findByPage();
        // 封装pageInfo对象
        PageInfo<Note> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
